﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;
using Microsoft.Practices.EnterpriseLibrary.Validation;


namespace Model
{
    [HasSelfValidation]
    public class Customer
    {
        [Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidator(1,25, Ruleset = "RuleSetA", 
        MessageTemplate="Mandatory")]
        public string FirstName { get; set; }
        [ValidatorComposition(CompositionType.Or, Ruleset = "RuleSetA", MessageTemplate = "max 10")]
        [NotNullValidator(Negated = true, Ruleset = "RuleSetA")]
        [StringLengthValidator(10, Ruleset = "RuleSetA", MessageTemplate = "max 10")]
        public string LastName { get; set; }

       
        public int? LowMark { get; set; }

     
        public int? HighMark { get; set; }

        [SelfValidation (Ruleset = "RuleSetA")]
         public  void CustomValidate( ValidationResults results)
        {
           
            if (LowMark.HasValue & HighMark.HasValue)
            {
                if (LowMark.Value >= HighMark.Value)
                {
                    results.AddResult(new ValidationResult("highmark must be gretaer than lowmark",
                    this, "", "", null));
                }
            }
        }

    }


   

}
